<link rel="stylesheet" type="text/css" href="assets/bootstrap-datepicker/css/datepicker.css" />
<aside class="lg-side">
  <div class="panel-heading tab-bg-dark-navy-blue okr-tab-head tab-right "></div>
  <div class="inbox-body mi-h8">
    <div class="row">
      <div class="col-lg-12">
        <section class="panel">
          <header class="panel-heading">
            拜访记录
          </header>
          <div class="panel-body">
            <form>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">客户公司名称*</label>
                <div class="col-sm-10">
                  <select class="form-control" name="comId" id="comId">
                    <option value="">请选择</option>
                  </select>
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">客户人员名称*</label>
                <div class="col-sm-10">
                    <input type="text" value="" autocomplete="off" certus-required id="cusName" name="customerName" class="form-control"
                    onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');" placeholder="请输入客户名称，自动检索，点击选中即可！" />
                  <input type="hidden" autocomplete="off" value="" id="cusId" name="userId" />
                  <!-- <input type="text" name="customerName" id="customerName" class="form-control" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');"> -->
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">拜访日期*</label>
                <div class="col-sm-10">
                  <input type="text" id="time" class="form-control" name="visitTime" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');">
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">拜访人(项目成员)*</label>
                <div class="col-sm-10">
                  <select class="form-control" name="userId" id="userId">
                    <option value="">请选择</option>
                  </select>
                  <!--<input type="text" value="" id="autocomplete" class="form-control" autocomplete="off">-->
                  <!--<input type="hidden" value="" id="userId">-->
                </div>
              </div>
              <div class="form-group customerForm">
                <label class="col-sm-2 control-label">拜访内容*</label>
                <div class="col-sm-10">
                  <textarea class="form-control" id="content" name="content" maxlength="120" placeholder="字数限制(120字以内)" onkeyup="this.value=this.value.replace(/(^\s+)|(\s+$)/g,'');"></textarea>
                </div>
              </div>
              <p class="default-buttons">
                <a href="javascript:void(0);" class="button-back btn btn-info" onclick="toBack()">返回</a>
                <a href="javascript:void(0);" class="button-next  btn btn-info vsubmit">提交</a>
              </p>
            </form>
          </div>
        </section>
      </div>
    </div>
  </div>
</aside>
<script type="text/javascript" src="js/autocomplete/jquery.autocomplete.js"></script>
<script type="text/javascript" src="assets/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script>
  $('#time').datepicker({
    format: 'yyyy-mm-dd'
  });

  $certusUtils.ajax("findCompOName", {}, function (response) {
      var data = response.data;
      for (var i = 0; i < data.length; i++) {
          $("#comId").append("<option value='" + data[i].id + "'>" + data[i].comName + "</option>");
      }
  });

  //项目成员
  $certusUtils.ajax("findMemberList", {
      "proId": proId
  }, function (response) {
      var data = response.data;
      for (var i = 0; i < data.length; i++) {
          $("#userId").append("<option value='" + data[i].userId + "'>" + data[i].userName + "</option>");
      }
  });

  $(".vsubmit").on('click', function () {
      if ($("#comId").val() == "" || $("#comId").val() == null || $("#comId").val() == undefined) {
          layer.msg("客户公司名称不能为空!");
          return;
      }

      if ($("#cusName").val() == "" || $("#cusName").val() == null || $("#cusName").val() == undefined) {
          layer.msg("客户人员名称不能为空!");
          return;
      }
      if ($("#time").val() == "" || $("#time").val() == null || $("#time").val() == undefined) {
          layer.msg("拜访时间不能为空!");
          return;
      }
      if ($("#userId").val() == "" || $("#userId").val() == null || $("#userId").val() == undefined) {
          layer.msg("拜访人不能为空!");
          return;
      }
      if ($("#content").val() == "" || $("#content").val() == null || $("#content").val() == undefined) {
          layer.msg("拜访内容不能为空!");
          return;
      }
      var arr = $("form").serializeArray();
      var data = {};
      for (var i = 0; i < arr.length; i++) {
          data[arr[i].name] = arr[i].value;
      };
      data.proId = proId;
      data.visitTime = $("#time").val();
      $certusUtils.ajax("addVisit", {
          "params": JSON.stringify(data)
      }, function () {
          layer.msg("添加成功！");
          toLoadHtml(4, 2);
      })
  });

  // 选择关联客户-客户自动补全
$certusUtils.ajax("findComList", {}, function (response) {
	var nhlTeams = [];
	var data = response.data;
	for (var i = 0; i < data.length; i++) {
		var arr = {};
		arr.name = data[i].comName + "（" + data[i].comShortName + "）-----" + data[i].userName;
		arr.id = data[i].id;
		nhlTeams.push(arr);
	}
	//自动补全
	var nhl = $.map(nhlTeams, function (obj) {
		return {
			value: obj.name,
			data: { category: obj.id }
		};
	});
	$('#cusName').devbridgeAutocomplete({
		lookup: nhl,
		minChars: 1,
		onSelect: function (suggestion) {
			$("#cusId").val(suggestion.data.category);
			// var cusName = $("#customerName").val().split("-----");
			// customerSearch(suggestion.data.category);
			// customerClean();
			// console.log(customerArry)
		},
		showNoSuggestionNotice: true,
		noSuggestionNotice: 'Sorry, no matching results'
	});
});

  function toBack() {
      toLoadHtml(4, 2);
  }
</script>